﻿var usercount = 1; var usercate = 0; var indexCount = 1; var cateStrid = 0;

function getItemCate(index, cateid, progress_id, cateStr) {
   

    $(cateStr).addClass("liBg").siblings().removeClass("liBg"); if (cateid != usercate || progress_id != cateStrid) { $("#m_show_more").html("查看更多"); } 
    usercount = 0; usercate = cateid; cateStrid = progress_id; 
    getUsers(index, usercate, cateStrid);
}



//获取项目列表
function getUsers(index, cateid, progress_id) {
    var idStr = "";
    //var idStr = $.query.get("str"); 
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "1210", "pageIndex": index, "cateid": cateid, "idStr": idStr, "isState": progress_id },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {

                usercount = data.count;
                var item = '';  var item_url = '';
                for (var i = 0; i < data.list.length; i++) {
                    item_url = "m_proPage.html?proid=" + data.list[i].Guid;
                    var userState = '';
                    var userStateID = data.list[i].IsState;

                    if (userStateID == 1) { userState = "<input class=\"btn_jr\" type=\"button\" onclick=\"apply_join('" + data.list[i].Guid + "')\" value=\"申请加入\">"; } else { userState = "<input class=\"btn_xq\" type=\"button\" onclick=\"GetLinkUrl('m_proPage.html?proid=" + data.list[i].Guid + "')\" value=\"查看详情\">"; }
                    var itemCount = ''; 
                    switch (data.list[i].ItemCount)
                    {
                        case 1: itemCount = '1~5 人'; break;
                        case 2: itemCount = '6~10 人'; break;
                        case 3: itemCount = '11~15 人'; break;
                        case 4: itemCount = '16~20 人'; break;
                        case 5: itemCount = '20以上'; break;
                        case 6: itemCount = '不限'; break;
                    }


                    item += " <div class=\"div_content\"><a style=\"color:#666;\" href=\"" + item_url + " \"><img class=\"zmz\" src=\"images/m_state_" + userStateID + ".png\"> <p class=\"p_title\">" + data.list[i].Title + "</p><ul class=\"ul_box\" style=\"list-style-type: disc;\"><li>预算：<span>" + moneyChange_Format(data.list[i].ItemBbudget) + "</span></li><li>已申请：<span>" + data.list[i].ApplyCount + "人</span></li> <li>项目人数：<span>" + itemCount + "</span></li> <li>项目周期：<span>" + dateChange_Format(data.list[i].ItemCycle) + "</span></li></ul> <p class=\"p_yq\">人员要求：<span>" + data.list[i].ItemRequire + "</span></p> </a><p class=\"p_btn\">" + userState + "</p></div>";
                        

                }


                $("#m_indexCount").val(usercount);
                if (index == 1) { $("#item_list").html(item); } else {
                    $("#item_list").append(item);  //项目 
                }
            } else { alert(data.msg); }
        }
    });

}
//项目分类
function GetItem_Cate() {

    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "110" },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {

                usercount = data.count;
               //var con = ' <li class=\"liBg\" onclick=\" getItemCate(1,0,0,this);\">全部</li>';
                var con = '';
                for (var i = 0; i < data.list.length; i++) {
                    con += "  <li onclick=\" getItemCate(1," + data.list[i].ID + ",0,this);\">" + data.list[i].ClassName + "</li> ";
                }
                $("#zs_cate").html(con);
            } else { alert(data.msg); }
        }
    });

}
//周期格式化
function dateChange_Format(dayStr) {
    var dStr = "";
    if (dayStr >= 100) { dStr = (parseInt(dayStr) / 30).toFixed(0) + "月"; } else if (dayStr >= 1000) { dStr =  (parseInt(dayStr) / 365).toFixed(0) + "年"; } else { dStr =  dayStr + "天"; }

    return dStr;
}
//预算格式化
function moneyChange_Format(dayStr) {
    var dStr = '';
    var fStr;

    if (dayStr < 100) { dStr = "<span>" + dayStr + "</span><span>&nbsp;&nbsp;元</span>"; }
    else if (dayStr >= 100 && dayStr <= 1000000) {

        fStr = (dayStr / 10000).toFixed(2);


        fStr = fStr.split('.');

        dStr = "<span>" + fStr[0] + "</span><span>." + fStr[1] + "&nbsp;&nbsp;万</span>";
    } else if (dayStr >= 1000000 && dayStr <= 100000000) {
        fStr = (dayStr / 1000000).toFixed(2);
        fStr = fStr.split('.');

        dStr = "<span>" + fStr[0] + "</span><span>." + fStr[1] + "&nbsp;&nbsp;百万</span>";
    } else { dStr = "<span>1</span><span>亿起</span>"; }
    return dStr;
}
function apply_join(proid) {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 114, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var joinBtnStr = '';

                switch (data.isLogin) {
                    case '0': alert('请先登录！'); GetLinkUrl("m_login.html"); break;
                    case '2': alert('请补全详细资料'); GetLinkUrl("m_perInfo.html"); break;
                    case '1': alert('申请已经提交！'); GetLinkUrl("m_proPage.html?proid=" + proid); break;
                    case '-1': alert('已经提交过申请！'); break;
                    case '-2': alert('已经加入！'); break;
                }

            }
        }
    });
}
function GetLinkUrl(url) { window.location.href = url; }
function GetItemData() {
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 1110, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $("#pro_title,#pro_title2").html(data.info.Title);
                $("#m_pro_title").html(data.info.Title + " -- 思高乐传媒，科研知识共享，项目对接，科研人才，学术项目合作");
                $("#pro_desc").html(data.info.Descriptions);
                var joinBtn = '';
                if (data.info.IsState == 1) {
                    joinBtn = '<input class="btn_sqjr" type="button" onclick=\"apply_join(\'' + data.info.Guid + '\')\" value="申请加入"> ';

                    switch (data.isLogin) {
                        case '-1': joinBtn = '  <input class="btn_sqjr" type="button" value="已经提交申请">'; break;
                        case '-2': joinBtn = ' <input class="btn_sqjr" type="button" value="已经加入">'; break;
                    }
                }
                $("#pro_btn_join").html(joinBtn);
                $("#pro_isstate").attr("src", "images/itemState_" + data.info.IsState + ".png");
                $("#pro_Cate").html(data.info.CategoryName);
                var countStr = '';
                switch (data.info.ItemCount) {
                    case 1: countStr = '1~ 5 人'; break
                    case 2: countStr = '6~ 10 人'; break
                    case 3: countStr = '11~ 15 人'; break
                    case 4: countStr = '16~ 20 人'; break
                    case 5: countStr = '20人以上'; break
                    case 6: countStr = '不限人数'; break
                }

                $("#pro_ItemCount").html(countStr);
                $("#pro_ItemUser").html(data.info.ItemUser);
                $("#pro_ItemTel").html("联系电话：<span style='color:red;width:200px;'>" + data.info.ItemTel+"</span>");
                $("#pro_ItemEmail").html("邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：<span style='color:red;width:200px;'>" + data.info.ItemEmail + "</span>");
                $("#pro_ItemRequire").html("人员要求：" + data.info.ItemRequire);
                $("#pro_Tag").html("标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;签：" + data.info.ItemTag);
                $("#pro_ItemBbudget").html(((data.info.ItemBbudget / 10000).toFixed(2)));
                $("#pro_ItemCycle").html(data.info.ItemCycle);
                $("#pro_ApplyCount").html(data.info.ApplyCount);
                $("#pro_JoinCount").html(data.info.JoinCount);
                $("#pro_JoinTime").html("招募时间："+GetFormatDate(data.info.RecruitStart) + " 至 " + GetFormatDate(data.info.RecruitEnd));
                $("#pro_StartTime").html("启动时间："+GetFormatDate(data.info.StartTime) + " 至 " + GetFormatDate(data.info.EndTime));
                $("#pro_Surplus").html(data.isDays);
                $("#pro_CategoryName").html("项目类别：" + data.info.CategoryName);
                $("#pro_ItemUser").html("负&nbsp;&nbsp;责&nbsp;&nbsp;人：" + data.info.ItemUser);
             
                 getUsersReply(1);


            }
        }
    });
}
//申请加入
function apply_join(proid) {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 114, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var joinBtnStr = '';

                switch (data.isLogin) {
                    case '0': alert('请先登录！'); GetLinkUrl("m_login.html"); break;
                    case '2': alert('请补全详细资料'); GetLinkUrl("m_perInfo.html?proid=" + proid); break;
                    case '1': alert('申请已经提交！'); if (proid == '3FC50CE4-ED47-4F86-9CE4-E342E7CA9A8B') { window.location.href = "m_qrCode.html"; } $("#btn_send_apply").hide(); $("#pro_btn_join").html("已经提交申请"); break;
                    case '-1': alert('已经提交过申请！'); break;
                    case '-2': alert('已经加入！'); break;
                }

            }
        }
    });
}
//申请加入的人员
function GetApplyUser(index) {
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 1120, "proid": proid, "pageIndex": index },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var con = '';

                for (var i = 0; i < data.list.length; i++) {
                    con += "  <li><span class=\"twoSpan\">" + data.list[i].NickName + "</span><span class=\"lastSpan\">" + data.list[i].TimeDate + "</span></li>";
                }
                $("#apply_indexCount").text(data.count);
                if (index == 1) { $("#pro_apply_user").html(con); } else {
                    $("#pro_apply_user").append(con);  //项目 
                }

            }
        }
    });
}
//已通过的人员
function GetJoinUser(index) {
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 1130, "proid": proid, "pageIndex": index },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var con = '';
                for (var i = 0; i < data.list.length; i++) {
                    con += "  <li><span class=\"twoSpan\">" + data.list[i].NickName + "</span><span class=\"lastSpan\">" + (data.list[i].IsState == 1 ? "通过" : "") + "</span></li>";
                }
                $("#join_indexCount").text(data.count);
                if (index == 1) { $("#pro_join_user").html(con); } else {
                    $("#pro_join_user").append(con);  //项目 
                }


            }
        }
    });
}



//获取项目评论列表
function getUsersReply(index) {
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "128", "pageIndex": index, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
               
                usercount = data.count;
                var item = ''; var userState = ''; var item_url = '';
                for (var i = 0; i < data.list.length; i++) {
                    item += " <li> <p><span style=\"color: #47A6F8;\">" + data.list[i].UNickName + "</span><span style=\"float: right;\">" + data.list[i].TimeDate + "</span></p> <p>" + data.list[i].PointDesc + "</p></li>";
                       
                }
                $("#item_com_list").html(item);  //项目评论 
                $("#m_indexCount").val(usercount);
            } else { alert(data.msg); }
        }
    });

}

//评论
function GetSendComment() {
    var item_desc = $("#item_desc_add").val();
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 127, "descStr": item_desc, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {

                alert("评论成功");
                getUsersReply(1);
            } else { alert(data.msg); }
        }
    });
}